import React from 'react';
import { Modal, Form } from 'antd';
import FormCondition from '@/components/FormCondition';
import { connect } from 'umi';
const ModalPrice = (props) => {
  const { visible = false, onClose, loading, handleReload, dispatch } = props;
  const { show = false, details = {} } = visible;
  const { id } = details;
  const [form] = Form.useForm();

  // 确认提交
  const handleUpAudit = () => {
    form.validateFields().then((values) => {
      dispatch({
        type: 'liveStreaming/fakeGoodsPrice',
        payload: { id, ...values },
        callback: () => {
          handleReload()
          onClose()
        }
      });

    });
  };

  const formItems = [
    {
      label: `商品售价`,
      type: 'number',
      name: 'price',
    },
  ];

  const modalProps = {
    title: '修改价格',
    width: 650,
    visible: show,
    maskClosable: true,
    destroyOnClose: true,
    zIndex: 1001,
    confirmLoading: loading,
  };

  return (
    <Modal {...modalProps} onCancel={onClose} onOk={handleUpAudit}>
      <FormCondition form={form} formItems={formItems} initialValues={details}></FormCondition>
    </Modal>
  );
};

export default connect(({ loading }) => ({
  loading: loading.models.liveStreaming,
}))(ModalPrice);;
